package com.it.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.demo.entity.Acl;
import com.it.demo.entity.Permission;
import com.it.demo.mapper.AclMapper;
import com.it.demo.service.AclService;
import com.it.demo.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@Slf4j
public class AclServiceImpl extends ServiceImpl<AclMapper, Acl> implements AclService {

    @Resource
    PermissionService permissionService;

    @Override
    public List<Permission> findByUserId(Integer id) {
        List<Acl> acls = baseMapper.selectList(new LambdaQueryWrapper<Acl>().eq(Acl::getUserId, id));
        Set<Integer> permIds = acls.stream().map(Acl::getPermissionId).collect(Collectors.toSet());
        return permissionService.findByIds(permIds);
    }


}
